// src/main/java/chessGame/Board.java
package chessGame;

import chessGame.piece.Piece;
import chessLib.Position;

import java.util.*;

//棋盘
public class Board {
    //使用位置和棋子的名字来表示当前棋子所在的位置
    private final Map<Position, Piece> pieces = new HashMap<>();

    public void placePiece(Piece piece, Position position) {
        pieces.put(position, piece);
    }

    public void movePiece(Position from, Position to) {
        if (!pieces.containsKey(from)) {
            throw new IllegalArgumentException("No piece at position " + from);
        }

        Piece piece = pieces.remove(from);
        pieces.put(to, piece);
    }

    public Piece getPieceAt(Position position) {
        return pieces.get(position);
    }

    public boolean isOccupied(Position position) {
        return pieces.containsKey(position);
    }

    public Set<Map.Entry<Position, Piece>> getAllPieces() {
        return pieces.entrySet();
    }

    public List<Position> getPiecePositions() {
        return new ArrayList<>(pieces.keySet());
    }
}
